// iframe id = resume_iframe

// 申明对应的click函数:
// 个人信息添加:
$("#per_add_button").click(function () {
    // 获取到子窗口per_name元素对象并修改其值为per_name输入框的值:
    $("#resume_iframe").contents().find("#per_name").text($("#per_name").val());
    // 性别
    $("#resume_iframe").contents().find("#per_sex").text($("#per_sex").val());
    // 生日
    $("#resume_iframe").contents().find("#per_birth").text($("#per_birth").val());
    // 电话
    $("#resume_iframe").contents().find("#per_phone").text($("#per_phone").val());
    // 邮件
    $("#resume_iframe").contents().find("#per_emil").text($("#per_emil").val());
    // 籍贯
    $("#resume_iframe").contents().find("#per_hometown").text($("#per_hometown").val());
    // 学历
    $("#resume_iframe").contents().find("#per_education").text($("#per_education").val());
    // 求职意向
    $("#resume_iframe").contents().find("#per_post").text($("#per_post").val());

});

// 个人信息重置(清除):
$("#per_remove_button").click(function () {
    alert("重置");
    // 获取到子窗口per_name元素对象并修改其值为per_name输入框的值:
    $("#resume_iframe").contents().find("#per_name").text("");
    // 性别
    $("#resume_iframe").contents().find("#per_sex").text("");
    // 生日
    $("#resume_iframe").contents().find("#per_birth").text("");
    // 电话
    $("#resume_iframe").contents().find("#per_phone").text("");
    // 邮件
    $("#resume_iframe").contents().find("#per_emil").text("");
    // 籍贯
    $("#resume_iframe").contents().find("#per_hometown").text("");
    // 学历
    $("#resume_iframe").contents().find("#per_education").text("");
    // 求职意向
    $("#resume_iframe").contents().find("#per_post").text("");

});

// 教育背景添加与追加:
$("#edu_add_button").click(function () {
    // 获取到resume页面对应的元素.
    var school = $("#resume_iframe").contents().find("#edu_school");
    var profession = $("#resume_iframe").contents().find("#edu_profession");
    var time = $("#resume_iframe").contents().find("#edu_time");

    // 如果默认的第一条为空,则修改其内容
    if(school.text() == "" && profession.text()=="" && time.text()==""){
        // 获取对应的子窗口学校的元素.
        school.text($("#edu_school").val());
        // 专业
        profession.text($("#edu_profession").val());
        // 时间
        time.text($("#edu_time").val());
    }
    // 否则则添加一条新片段.
    else{
        // 声明片段,并将输入的对应内容引入到片段中
        var edu_html = "<tr id='edu_tr_1' class=\"edu_tr\">\n" +
            "            <th id=\"edu_school\" colspan=\"2\">"+$("#edu_school").val()+"</th>\n" +
            "            <th id=\"edu_profession\" colspan=\"2\">"+$("#edu_profession").val()+"</th>\n" +
            "            <th id=\"edu_time\" colspan=\"3\">"+$("#edu_time").val()+"</th>\n" +
            "        </tr>"

        // 在对应的元素之前引入
        $("#resume_iframe").contents().find("#filed_tr").before(edu_html);
    };

});

// 教育背景重置:
$("#edu_remove_button").click(function () {
    // 首先,去除默认内容
   $("#resume_iframe").contents().find("#edu_school").text("");
   $("#resume_iframe").contents().find("#edu_profession").text("");
   $("#resume_iframe").contents().find("#edu_time").text("");

   // 找到 edu_tr_1 去除
    $("#resume_iframe").contents().find("#edu_tr_1").remove();

    // 去除描述信息
    $("#resume_iframe").contents().find("#edu_description_1").remove();
});

// 教育背景描述追加:
$("#edu_append_description").click(function () {

    // 判断一下,当输入栏值为空时,不插入片段
    if($("#edu_description").val() != ""){
        // 申明描述片段,并将对应的输入框内容引入到对应的位置
        var edu_description_html = "<tr id='edu_description_1'>\n" +
            "            <td class=\"description_td\" colspan=\"7\"><pre id=\"edu_description\">"+$("#edu_description").val()+"</pre></td>\n" +
            "        </tr>"

        // 在对应的元素之前插入html片段
        $("#resume_iframe").contents().find("#filed_tr").before(edu_description_html);
    }
});

// 实习经历添加:
$("#filed_add_button").click(function () {

    // 获取元素对象的text值.
    var company =  $("#resume_iframe").contents().find("#filed_company");
    var post =  $("#resume_iframe").contents().find("#filed_post");
    var time =  $("#resume_iframe").contents().find("#filed_time");
    var description =  $("#resume_iframe").contents().find("#filed_description");
    // 通过if判断表格内容来控制是添加还是追加新片段.
    if(company.text()=="" && post.text()=="" && time.text()=="" && description.text()==""){
        company.text($("#filed_company").val());
        post.text($("#filed_post").val());
        time.text($("#filed_time").val());
        description.text($("#filed_description").val());
    }
    // 否则,添加新片段.
    else {
        // 申明片段并添加内容
        var filed_html = "  <tr id='file_tr_1' class=\"file_tr\">\n" +
            "            <th id=\"filed_company\" colspan=\"2\">"+$("#filed_company").val()+"</th>\n" +
            "            <th id=\"filed_post\" colspan=\"2\">"+$("#filed_post").val()+"</th>\n" +
            "            <th id=\"filed_time\" colspan=\"3\">"+$("#filed_time").val()+"</th>\n" +
            "        </tr>\n" +
            "        <tr id='file_description_1'>\n" +
            "            <td class=\"description_td\" colspan=\"7\"><pre id=\"filed_description\">"+$("#filed_description").val()+"</pre></td>\n" +
            "        </tr>"

        // 追加html片段.
        $("#resume_iframe").contents().find("#project_tr").before(filed_html);
    };
});


// 实习经历重置:
$("#filed_remove_button").click(function () {
        $("#resume_iframe").contents().find("#filed_company").text("");
        $("#resume_iframe").contents().find("#filed_post").text("");
        $("#resume_iframe").contents().find("#filed_time").text("");
        $("#resume_iframe").contents().find("#filed_description").text("");

    $("#resume_iframe").contents().find("#file_tr_1").remove();
    $("#resume_iframe").contents().find("#file_description_1").remove();
});

// 项目经历添加或追加:
$("#project_add_button").click(function () {
    // 获取对象
    var name = $("#resume_iframe").contents().find("#project_name");
    var time = $("#resume_iframe").contents().find("#project_time");
    var description = $("#resume_iframe").contents().find("#project_description");
    if(name.text() == "" && time.text() == "" && description.text() == ""){
        name.text($("#project_name").val());
        time.text($("#project_time").val());
        description.text($("#project_description").val());
    }
    else{
        // 申明片段
        var project_html = "  <tr id='project_tr_1' class=\"project_tr\">\n" +
            "            <th id=\"project_name\" colspan=\"4\">"+$("#project_name").val()+"</th>\n" +
            "            <th id=\"project_time\" colspan=\"3\">"+$("#project_time").val()+"</th>\n" +
            "        </tr>\n" +
            "        <tr id='project_description_1'>\n" +
            "            <td class=\"description_td\" colspan=\"7\"><pre id=\"project_description\">"+$("#project_description").val()+"</pre></td>\n" +
            "        </tr>"

        // 对应元素插入片段
        $("#resume_iframe").contents().find("#skill_tr").before(project_html);
    }
});

// 项目经历重置:
$("#project_remove_button").click(function () {
     $("#resume_iframe").contents().find("#project_name").text("");
     $("#resume_iframe").contents().find("#project_time").text("");
     $("#resume_iframe").contents().find("#project_description").text("");

    $("#resume_iframe").contents().find("#project_tr_1").remove();
    $("#resume_iframe").contents().find("#project_description_1").remove();
});

// 个人技能添加:
$("#skill_add_button").click(function () {
    var name = $("#resume_iframe").contents().find("#skill_name");
    var degree = $("#resume_iframe").contents().find("#skill_degree");
    // 判断元素内容
    if (name.text()=="" && degree.text()==""){
        name.text($("#skill_name").val());
        degree.text($("#skill_degree").val());
        degree.css({"width":""+$("#skill_degree").val()+""});
    }
    else {
        var skill_html = "<tr id='skill_tr_1' class=\"skill_tr\">\n" +
            "            <th id=\"skill_name\">"+$("#skill_name").val()+"</th>\n" +
            "            <th colspan=\"9\">\n" +
            "            <div id=\"skill_degree\" class=\"degree\" style=\"width: "+$("#skill_degree").val()+"\">"+$("#skill_degree").val()+"</div>\n" +
            "            </th>\n" +
            "        </tr>"

        // 插入html片段
        $("#resume_iframe").contents().find("#hobby_tr").before(skill_html);
    };
});

// 个人技能重置:
$("#skill_remove_button").click(function () {
    $("#resume_iframe").contents().find("#skill_name").text("");
    $("#resume_iframe").contents().find("#skill_degree").text("");
    $("#resume_iframe").contents().find("#skill_tr_1").remove();
});
// 兴趣爱好添加(其实是添加html模板片段):
$("#hobby_add_button").click(function () {

    // 获取到当前输入的爱好名称
    var hobby_name = $("#hobby_name").val();
    // 定义模板片段
    var hobby_html = "<div id=\"hobby_box\" class=\"hobby_box\">"+hobby_name+"</div>"

    // 添加模板
    $("#resume_iframe").contents().find("#hobby_name").append(hobby_html);
});

// 是否添加兴趣爱好描述:
$("#hobby_description_add").click(function () {
    $("#resume_iframe").contents().find("#hobby_description").text($("#hobby_description").val());
});

// 兴趣爱好重置:
$("#hobby_remove_button").click(function () {
    // 清空hooby_name下的子元素
    $("#resume_iframe").contents().find("#hobby_name").empty();
    $("#resume_iframe").contents().find("#hobby_description").text("");

});
